#ifndef SOLUTION_H_
#define SOLUTION_H_
#ifndef NULL
#define NULL 0
#endif
class Solution {
public:
    int lengthOfLastWord(const char *s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		const char* wordStart = NULL, *wordEnd = NULL;
		bool wordFound = false;

		const char* cur = s;
		while(*cur)
		{
			if(*cur == ' ')
			{
				if(wordFound)
				{
					wordEnd = cur;
					wordFound = false;
				}
			}
			else
			{
				if(!wordFound)
				{
					wordStart = cur;
					wordFound = true;
				}
			}
			cur++;
		}

        
		if(wordStart != NULL)
		{
			if(wordEnd > wordStart)
				return wordEnd-wordStart;
			else
				return cur-wordStart;
		}
		else
			return 0;
    }
};
#endif